package cz.mendelu.swi2.spravaUzivatelu.model;

import java.util.ArrayList;
import java.util.List;

import cz.mendelu.swi2.skladDilu.User;

public class UserManager implements IUserManager {
	private ArrayList<IUser> users;
	private int idCounter;

	public UserManager() {
		users = new ArrayList<IUser>();
		this.idCounter = 0;
	}

	@Override
	public List<IUser> getAllUsers() {
		return users;
	}

	@Override
	public IUser getUserByEmail(String email) {
		for (IUser u : users) {
			if (u.getEmail().equals(email))
				return u;
		}
		return null;
	}

	@Override
	public IUser getUserById(int id) {
		for (IUser u : users) {
			if (u.getId() == id)
				return u;
		}
		return null;
	}

	@Override
	public boolean addUser(IUser user) {
		user.setId(idCounter++);
		return users.add(user);
	}

	@Override
	public boolean deleteUser(IUser user) {
		return users.remove(user);
	}

	@Override
	public List<IUser> getUsersByRole(Role role) {
		List<IUser> l = new ArrayList<IUser>();
		for (IUser u : users) {
			if (u.getRole() == role) {
				l.add(u);
			}
		}
		return l;
	}
   
	
	
}
